<?php

use app\assets\TableAsset;
use app\widgets\ManagerTableOp;
use app\models\KeyMap;
use yii\helpers\Html;
use yii\helpers\Url;
use app\models\UserConfig;
use app\widgets\LinkPager;
/**
 * @var $this yii\web\View
 * @var $apiList app\models\Api[]
 */

TableAsset::register($this);

$this->title = '订单列表';
$this->params['breadcrumbs'][] = '出库管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
    <div class="form-group">
        <a href="<?php echo Url::to(['/admin/outbound/order-edit']);?>" class="btn btn-success btn-sm">添加</a>
    </div>
<div class="form-group">
    <label for="search_order" class="sr-only">订单号</label>
    <?php echo Html::textInput('orderno', Yii::$app->request->get('orderno'), ['order' => 'orderno', 'class' => 'form-control', 'placeholder' => '订单号', 'style' => 'width: 120px;']);?>
</div>
<div class="form-group">
    <button class="btn btn-primary btn-sm">搜索</button>
</div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th class="center">
                <label class="pos-rel">
                    <input type="checkbox" class="ace" />
                    <span class="lbl"></span>
                </label>
            </th>
            <th>订单号</th>
            <th>订单名称</th>
            <th>用户</th>
            <th>代理商</th>
            <th>运营商</th>
            <th>套餐</th>
            <th>卡类型</th>
            <th>单价</th>
            <th>数量</th>
            <th>金额</th>
            <th>支付方式</th>
            <th>发票</th>
            <th>出库状态</th>
            <th>创建日期</th>
            <th>操作</th>
        </tr>
    </thead>

    <tbody>
        <?php foreach ($orderList as $order) {?>
            <tr id="data_<?php echo $order->id;?>">
                <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $order->id;?>" /><span class="lbl"><?php echo $order->id;?></span></label></td>
                <td><?php echo Html::encode($order->orderno);?></td>
                <td><?php echo Html::encode($order->titles);?></td>
                <td><?php echo Html::encode($order->username);?></td>
                <td><?php echo Html::encode($order->agentname);?></td>
                <td><?php echo Html::encode($order->isp->name);?></td>
                <td><?php echo Html::encode($order->package->name);?></td>
                <td><?php echo Html::encode($order->cardtype->name);?></td>
                <td><?php echo Html::encode($order->price);?></td>
                <td><?php echo Html::encode($order->number);?></td>
                <td><?php echo Html::encode($order->amount);?></td>
                <!--<td><?php /*$prepaidPostpaid = UserConfig::getConfig($order->user->id, 'prepaid_postpaid', '');
                    echo ['' => '', 'prepaid' => '预付费', 'postpaid' => '后付费'][$prepaidPostpaid];
                    */?></td>-->
                <td><?php echo KeyMap::getValue('payment_type',$order->payment_type)?></td>

                <td><?php echo KeyMap::getValue('yes_no', $order->need_invoice);?></td>
                <td><?php
                    if($order->status==0){
                        echo '<span style="color:red">未出库</span>';
                    }else{
                        echo "已出库";
                    }
                    ?></td>
                <td><?php echo Yii::$app->formatter->asDateTime($order->create_time);?></td>
                <td><?php echo ManagerTableOp::widget(['items' => [
                        ['icon' => 'fa fa-pencil', 'href' => Url::to(['/admin/outbound/order-edit', 'id' => $order->id]), 'btn_class' => 'btn btn-xs btn-success', 'tip' => '修改', 'color' => 'green'],
                        ['icon' => 'fa fa-trash', 'onclick' => 'deleteOrder(' . $order->id . ')', 'btn_class' => 'btn btn-xs btn-danger', 'tip' => '删除'],
                    ]]);?></td>
            </tr>
        <?php }?>
    </tbody>
</table>
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
<script>
    /**
     * 删除订单
     * @param id int 订单编号
     */
    function deleteOrder(id) {
        if (!confirm('确定要删除此订单吗？')) {
            return false;
        }
        $.getJSON('<?php echo Url::to(['/admin/outbound/order-delete']);?>', {id: id}, function (json) {
            /*if (callback(json)) {
                $('#data_' + id).remove();
            }*/
            if(json.result=="success"){
                alert('删除成功');
                history.go(0);
            }else{
                alert('删除失败');
            }
        });
    }
</script>
